package linwen.wang.swagger.service.impl;

import linwen.wang.common.resp.BaseResp;
import linwen.wang.swagger.service.UserService;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @ClassName UserServiceImpl
 * @Description
 * @Author lin
 * @Date 2022/3/29 下午9:58
 * @Version V1.0
 */
@Service
public class UserServiceImpl implements UserService {
    static ArrayList<UserVO> userVOs = new ArrayList<>();

    static {
        userVOs.add(UserVO.builder().id("1").userName("张三").sex("男").birthday(new Date(2021, 03, 12)).address("深圳").build());
        userVOs.add(UserVO.builder().id("2").userName("李四").sex("男").birthday(new Date(2021, 03, 12)).address("上海").build());
        userVOs.add(UserVO.builder().id("3").userName("王五").sex("男").birthday(new Date(2021, 03, 12)).address("广州").build());
        userVOs.add(UserVO.builder().id("4").userName("赵六").sex("女").birthday(new Date(2021, 03, 12)).address("北京").build());
        userVOs.add(UserVO.builder().id("5").userName("刘飞").sex("男").birthday(new Date(2021, 03, 12)).address("武威").build());
        userVOs.add(UserVO.builder().id("6").userName("楚楚").sex("女").birthday(new Date(2021, 03, 12)).address("兰州").build());
        userVOs.add(UserVO.builder().id("7").userName("大柱").sex("男").birthday(new Date(2021, 03, 12)).address("西宁").build());
        userVOs.add(UserVO.builder().id("8").userName("枕套").sex("男").birthday(new Date(2021, 03, 12)).address("新疆").build());
    }


    @Override
    public BaseResp getUserById(String id) {
        List<UserVO> userVOS = userVOs.stream().filter(u -> u.getId().equals(id)).limit(1).collect(Collectors.toList());
        if(userVOS.isEmpty()){
            return BaseResp.fail(400, "查询的用户不存在");
        }
        return BaseResp.success(userVOS.get(0));
    }
}
